import bpy
import nodeitems_utils
import engine.initLIB.load_dll as engineLib

from bpy.types import Header, Menu, Panel, Area




import ctypes
import sys
sys.path.append("D:/U/Project/BlenderSandbox/节点")


import 节点.bl_节点注册 as 节点注册

import 节点.全局控制.节点注册 as old_节点注册
import 全局控制.bl_场景节点 as 场景节点
import 节点.AN_节点.bl_AN_扩展节点注册 as AN_扩展节点注册
from 全局控制.Node import bl_ui_Node定位更新 as ui定位更新
import bl_节点菜单

import 节点.节点更新.update节点 as 节点更新

from 节点.节点更新 import bl_节点属性面板
from 节点.节点更新 import bl_节点DEBUG面板 





'''import bgl
import gpu
from gpu_extras.presets import draw_texture_2d
WIDTH = 512
HEIGHT = 256
offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT)
def draw():
	context = bpy.context
	scene = context.scene

	view_matrix = scene.camera.matrix_world.inverted()

	projection_matrix = scene.camera.calc_matrix_camera(
		context.depsgraph, x=WIDTH, y=HEIGHT)
		
	offscreen.draw_view3d(
		scene,
		context.view_layer,
		context.space_data,
		context.region,
		view_matrix,
		projection_matrix)
	
	engineLib.flexCAPI.f_渲染到纹理(ctypes.c_uint(offscreen.color_texture.numerator))

	bgl.glDisable(bgl.GL_DEPTH_TEST)
	draw_texture_2d(offscreen.color_texture, (10, 10), WIDTH, HEIGHT)
	
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')'''



def f_3D视口变化节点实时更新():
	for tree in bpy.data.node_groups:
		if tree.bl_idname == 'idname_场景对象操作节点树' and tree.m_父节点树 == None:
			tree.f_定点更新([])


注册类 = [
	bl_节点DEBUG面板,
	场景节点,
	节点注册,
	old_节点注册,
	
	
]





def f_initNodeGroups(scene):
	print('初始化节点组')
	
	


def register():
	for c in 注册类:
		c.register()
		#bpy.utils.register_class(c)
	
	
	bl_节点菜单.register()
	ui定位更新.register()
	
	节点更新.register()
	#bl_节点DEBUG面板.register()
	bl_节点属性面板.register()


	return
	#初始化
	for tree in bpy.data.node_groups:
		if tree.bl_idname == 'idname_场景对象操作节点树' and tree.m_父节点树 == None:
			tree.f_重新构建节点()
			
			if tree.m_当前绑定场景 :
				engineLib.flexCAPI.f_绑定节点树操作场景(ctypes.c_wchar_p(tree.name), ctypes.c_uint(tree.m_当前绑定场景.m_场景ID))

			tree.m_上一次链接数量 = len(tree.links)

			engineLib.flexCAPI.f_标记所有节点需更新(ctypes.c_wchar_p(tree.name))
			tree.f_定点更新([])
	#for tree in bpy.data.node_groups:
	engineLib.flexCAPI.f_node_初始化更新节点()
	
	#bpy.app.handlers.load_pre.append(f_initNodeGroups)
	#bpy.app.handlers.redo_post.append(f_initNodeGroups)
	#bpy.app.handlers.version_update.append(f_initNodeGroups)
	#handle_view = bpy.types.SpaceView3D.draw_handler_add(f_3D视口变化节点实时更新, (), 'WINDOW', 'POST_VIEW')


def unregister():
	for c in 注册类:
		c.unregister()
		#bpy.utils.unregister_class(c)
		

	bl_节点菜单.unregister()
	ui定位更新.unregister()

	节点更新.unregister()
	#bl_节点DEBUG面板.unregister()
	bl_节点属性面板.unregister()


#if __name__ == "__main__":
#	register()




